<?php
/**
* File that contains Application_Form_Admin_insertBusstop class.
* @package busmap
*/

/**
* Application_Form_Admin_insertBusstop class generates a form used to insert new busstops.
* There is a text field for the name of the busstop.
* Two text fields are used to assign numeric coordinates to the form (although it's easier to set these fields to an small random number and manipulate the added busstop afterwards from the map).
* @package busmap
*/
class Application_Form_Admin_insertBusStop extends Zend_Form
{
	/**
	* Initialize function generates and adds the elements described in the class description.
	*/
    public function init()
    {
        $this->setMethod('post');

		$this->addElement(
            'text', 'name', array(
                'required' => true,
                'filters'    => array('StringTrim'),
				'class' => 'bold-text'
            ));
		$this->name->addErrorMessage('Bussipeatuse nimi ei saa olla tühi');
		$this->name->addDecorator('HtmlTag', array('tag'=>'div', 'class'=>'data-listing data-listing-cell'));


		$this->addElement(
            'text', 'xCoordinate', array(
                'required' => true,
				'validators' => array('Alnum'),
				'class' => 'small-data'
            ));
		$this->xCoordinate->addErrorMessage('Bussipeatuse x-kordinaat peab olema number');
		$this->xCoordinate->addDecorator('HtmlTag', array('tag'=>'div', 'openOnly'=>true, 'class'=>'data-listing data-listing-cell'));

		$this->addElement(
            'text', 'yCoordinate', array(
                'required' => true,
				'validators' => array('Alnum'),
				'class' => 'small-data'
            ));
		$this->yCoordinate->addErrorMessage('Bussipeatuse y-kordinaat peab olema number');
		$this->yCoordinate->addDecorator('HtmlTag', array('tag'=>'div', 'closeOnly'=>true, 'class'=>'data-listing data-listing-cell'));

		 $this->addElement(
            'submit', 'addNew', array(
                'required' => false,
				'label' => 'Lisa',
				'class' => 'submit-data'
            ));
		$this->addNew->addDecorator('HtmlTag', array('tag'=>'div', 'class'=>'data-listing data-listing-cell-button'));

		$this->clearElementLabels();
		
    }

	/**
	* This function clears the label, DtDd and error decorators from all of the elements.
	* Errors are shown elsewhere in the view.
	*/
	public function clearElementLabels(){
		$elements = $this->getElements();
		foreach($elements as $element){
			$element->removeDecorator('label')->removeDecorator('DtDdWrapper')->removeDecorator('Errors');
		}
	}

}